package logik;

import gui.Screen;
import data.BankDatabase;

public class AuthenticateUser {

	private boolean userAuthenticated;
	private int currentAccountNumber;
	private BankDatabase bankDatabase;
	private Screen screen;
	
	public AuthenticateUser(Screen screen, BankDatabase bankDatabase){
		this.userAuthenticated = false;
		this.currentAccountNumber = 0;
		this.screen = screen;
		this.bankDatabase = bankDatabase;
	}
	
	public boolean getUsAu(){
		return userAuthenticated;
	}
	
	public int getAccNr(){
		return currentAccountNumber;
	}
	
	public void authenticateUser(){
		
		int accountNumber = 0;
		int pin = 0;
		
		accountNumber = screen.getWelcome().getAcc();
		pin = screen.getWelcome().getPin();
		System.out.println(pin);
		System.out.println(accountNumber);
		System.out.println(screen.getWelcome().getAcc());
		System.out.println(currentAccountNumber);
		userAuthenticated =
				bankDatabase.authenticateUser(accountNumber, pin );
		// check whether authentication succeeded
		if (userAuthenticated) {
			currentAccountNumber = accountNumber; // save user's account
		} // end if		
		else {
			System.out.println("Invalid account number or PIN. Please try again.");
		} // end else
	} // end method authenticateUser
}
